<template>
  <!-- 商品橱窗对话框 -->
  <div class="binding">
    <el-dialog
      title="绑定微信"
      :visible.sync="isBinding"
      width="30%"
      :before-close="cancel">
      <div class="binding-content">
        <div class="qrCode">
          <div id="login_container"></div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
          <el-button type="success" @click="binding">绑定</el-button>
          <el-button @click="cancel">取消</el-button>
        </span>
    </el-dialog>
  </div>
</template>

<script>
import '@/framework/utils/wxLogin'
import {authenticateByOpenCode} from "@/project/service/manager";

export default {
  name:'binding',
  props: {
    isBinding:{
      type: Boolean,
      default: () => {
        return false
      }
    }
  },
  data() {
    return {

    }
  },
  created(){
    this.wechatLogin()
  },
  methods: {
    //展示二维码
    wechatLogin() {
      let that = this
      new WxLogin({
        self_redirect: false,
        id: "login_container",
        appid: "wx1ac014b8d235957f",
        scope: "snsapi_login",
        // redirect_uri: encodeURIComponent(that.$store.state.targetUrl + '/login'),
        redirect_uri: encodeURIComponent(that.$store.state.targetUrl),
        state: "",
        style: ""
      })
    },
    // //微信登录
    // handleWechatLogin() {
    //   authenticateByOpenCode({platformCode: this.platformCode}, token=> {
    //     localStorage.setItem('agent_live_web_token', token)
    //     this.findWithMe()
    //     this.$router.push('/login/bind/'+this.platformCode)
    //   })
    // },
    //绑定
    binding(){
      this.cancel()
    },
    //取消
    cancel(){
      this.$emit('close',false)
    }
  }
}
</script>

<style lang="less" scoped>
.binding-content{
  width: 100%;

  .qrCode{
    text-align: center;

    img{
      width: 200px;
      height: 200px;
    }
  }
}
</style>
